/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

import java.io.Serializable;

import java.sql.Date;

import java.util.ArrayList;
import java.util.List;


/**
 * Imported survey header.
 */
public class SurveyAnswerHeaderImported implements Serializable {
	/**
	 * The identifier.
	 */
	private Long id;

	/**
	 * The creation date, when the user filled the form.
	 */
	private Date creationDate;

	/**
	 * The import date, when the form was imported in this system.
	 */
	private Date importDate;

	/**
	 * The action id.
	 */
	private Integer actionId;

	/**
	 * The action code.
	 */
	private String actionCode;

	/**
	 * The identifier of the person or company which filled the survey.
	 */
	private String entityId;

	/**
	 * The internet connection flag.
	 */
	private Integer internetConnection;

	/**
	 * The council where the form was filled, normally during a training action.
	 */
	private String councilId;

	/**
	 * The survey this answer header belongs to.
	 */
	private Integer surveyId;

	/**
	 * The survey this answer header belongs to.
	 */
	private String surveyCode;

	/**
	 * The state.
	 */
	private SurveyHeaderValidation status;

	/**
	 * The id origin.
	 */
	private AnswerOrigin origin;

	/**
	 * The file id.
	 */
	private ImportedFile importedFile;

	/**
	 * The unit answers, part of this filled survey.
	 */
	private List<SurveyUnitAnswerImported> unitAnswers;

/**
   * Constructor.
   */
	public SurveyAnswerHeaderImported() {
		importDate = new Date(System.currentTimeMillis());
		status = SurveyHeaderValidation.INVALID;
		origin = AnswerOrigin.LOAD;
		unitAnswers = new ArrayList<SurveyUnitAnswerImported>();
	}

	/**
	 * Retrieves the id.
	 *
	 * @return the id.
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Sets the id.
	 *
	 * @param id the id.
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Retrieves the creation date.
	 *
	 * @return the creation date.
	 */
	public Date getCreationDate() {
		return creationDate;
	}

	/**
	 * Sets the creation date.
	 *
	 * @param creationDate the creation date.
	 */
	public void setCreationDate(final Date creationDate) {
		this.creationDate = creationDate;
	}

	/**
	 * Retrieves the import date.
	 *
	 * @return the import date.
	 */
	public Date getImportDate() {
		return importDate;
	}

	/**
	 * Sets the import date.
	 *
	 * @param importDate the import date
	 */
	public void setImportDate(final Date importDate) {
		this.importDate = importDate;
	}

	/**
	 * Retrieves the action id.
	 *
	 * @return the action id.
	 */
	public Integer getActionId() {
		return actionId;
	}

	/**
	 * Sets the action id.
	 *
	 * @param actionId the action id.
	 */
	public void setActionId(final Integer actionId) {
		this.actionId = actionId;
	}

	/**
	 * Retrieves the entity id.
	 *
	 * @return the entity id.
	 */
	public String getEntityId() {
		return entityId;
	}

	/**
	 * Sets the entity id.
	 *
	 * @param entityId the entity id.
	 */
	public void setEntityId(final String entityId) {
		this.entityId = entityId;
	}

	/**
	 * Retrieves the internet collection.
	 *
	 * @return the internet collection.
	 */
	public Integer getInternetConnection() {
		return internetConnection;
	}

	/**
	 * Sets the internet collection.
	 *
	 * @param internetConnection the internet collection.
	 */
	public void setInternetConnection(final Integer internetConnection) {
		this.internetConnection = internetConnection;
	}

	/**
	 * Retrieves the council id.
	 *
	 * @return the council id.
	 */
	public String getCouncilId() {
		return councilId;
	}

	/**
	 * Sets the council id.
	 *
	 * @param councilId the council id.
	 */
	public void setCouncilId(final String councilId) {
		this.councilId = councilId;
	}

	/**
	 * Retrieves the survey id.
	 *
	 * @return the survey id.
	 */
	public Integer getSurveyId() {
		return surveyId;
	}

	/**
	 * Setes the survey id.
	 *
	 * @param surveyId the survey id.
	 */
	public void setSurveyId(final Integer surveyId) {
		this.surveyId = surveyId;
	}

	/**
	 * Retrieves the survey status.
	 *
	 * @return the survey status.
	 */
	public SurveyHeaderValidation getStatus() {
		return status;
	}

	/**
	 * Sets the survey status.
	 *
	 * @param status the survey status.
	 */
	public void setStatus(final SurveyHeaderValidation status) {
		this.status = status;
	}

	/**
	 * Retrieves the answer origin.
	 *
	 * @return the answer origin.
	 */
	public AnswerOrigin getOrigin() {
		return origin;
	}

	/**
	 * Sets the answer origin.
	 *
	 * @param origin the answer origin.
	 */
	public void setOrigin(final AnswerOrigin origin) {
		this.origin = origin;
	}

	/**
	 * Retrieves the imported file.
	 *
	 * @return the imported file.
	 */
	public ImportedFile getImportedFile() {
		return importedFile;
	}

	/**
	 * Sets the imported file.
	 *
	 * @param importedFile the imported file.
	 */
	public void setImportedFile(final ImportedFile importedFile) {
		this.importedFile = importedFile;
	}

	/**
	 * Retrieves the unit answers.
	 *
	 * @return the unit answers.
	 */
	public List<SurveyUnitAnswerImported> getUnitAnswers() {
		return unitAnswers;
	}

	/**
	 * Sets the unit answers.
	 *
	 * @param unitAnswers the unit answers.
	 */
	public void setUnitAnswers(final List<SurveyUnitAnswerImported> unitAnswers) {
		this.unitAnswers = unitAnswers;
	}

	/**
	 * Gets the action code.
	 *
	 * @return the action code
	 */
	public String getActionCode() {
		return actionCode;
	}

	/**
	 * Sets the action code.
	 *
	 * @param actionCode the new action code
	 */
	public void setActionCode(String actionCode) {
		this.actionCode = actionCode;
	}

	/**
	 * Gets the survey code.
	 *
	 * @return the survey code
	 */
	public String getSurveyCode() {
		return surveyCode;
	}

	/**
	 * Sets the survey code.
	 *
	 * @param surveyCode the new survey code
	 */
	public void setSurveyCode(String surveyCode) {
		this.surveyCode = surveyCode;
	}

	/**
	 * Add an answer.
	 *
	 * @param answer the answer.
	 */
	public void add(final SurveyUnitAnswerImported answer) {
		answer.setHeader(this);
		getUnitAnswers().add(answer);
	}

	/**
	 * Remove an answer.
	 *
	 * @param answer the answer.
	 */
	public void remove(final SurveyUnitAnswerImported answer) {
		getUnitAnswers().remove(answer);
		answer.setHeader(null);
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof SurveyAnswerHeaderImported)) {
			return false;
		}

		SurveyAnswerHeaderImported that = (SurveyAnswerHeaderImported)o;

		if((getId() != null) ? (!getId().equals(that.getId())) : (that.getId() != null)) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return (getId() != null) ? getId().hashCode() : 0;
	}
}
